package face.link;

/**
 * @author spf
 * @date 2024/9/5
 * @time 23:28
 */

/**
 * 链表删除元素
 */
public class RemoveElement {
    /**
     * 链表结构定义
     * @param args
     */
    static class ListNode{
        int val;
        ListNode next;

        public ListNode(int val){
            this.val = val;
            this.next = null;
        }
    }

    public static void main(String[] args){

    }

    public static ListNode removeElement(ListNode head, int val){
        ListNode pre = new ListNode(0);
        pre.next = head;
        ListNode h = pre;
        while(h.next !=null){
            if(h.next.val == val){
                h.next = h.next.next;
            }else{
                h = h.next;
            }
        }

        return pre.next;
    }
}
